css: Handle repeating gradients with only one offset
authorBenjamin Otte <otte@redhat.com>
Mon, 26 Dec 2016 16:04:56 +0000 (17:04 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 26 Dec 2016 16:22:01 +0000 (17:22 +0100)
Example:
  repeating-linear-gradient(red 50%, blue 50%)

Those gradients in Firefox draw a solid image of the last color, so do
the same here.

gtk/gtkcssimagelinear.c

index 17318cabb9208d4041a87d0200cc86770dc6e1ce..5841e1508f5ce26f049b1da6476fab441bf4fdf9 100644 (file)
@@ -181,6 +181,19 @@ gtk_css_image_linear_snapshot (GtkCssImage        *image,
   length = sqrt (x * x + y * y);
   gtk_css_image_linear_get_start_end (linear, length, &start, &end);
 
+  if (start == end)
+    {
+      /* repeating gradients with all color stops sharing the same offset
+       * get the color of the last color stop */
+      GtkCssImageLinearColorStop *stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, linear->stops->len - 1);
+
+      gtk_snapshot_append_color_node (snapshot,
+                                      _gtk_css_rgba_value_get_rgba (stop->color),
+                                      &GRAPHENE_RECT_INIT (0, 0, width, height),
+                                      "RepeatingLinearGradient<degenerate>");
+      return;
+    }
+
   offset = start;
   last = -1;
   stops = g_newa (GskColorStop, linear->stops->len);